package ce.com.cenewbluesdk.entity.k2;

import android.os.Parcel;
import android.os.Parcelable;

import ce.com.cenewbluesdk.CEBC;
import ce.com.cenewbluesdk.entity.BaseData;
import ce.com.cenewbluesdk.entity.CEDevData;
import ce.com.cenewbluesdk.uitl.ByteUtil;

/**
 * Created by Administrator on 2016/11/21 0021.
 */
public class K2_SendUserInfo extends BaseData implements Parcelable {

    byte[] userid = new byte[4];
    byte sex;
    byte age;
    byte height;
    byte weight;
    byte lr_hand;


    public K2_SendUserInfo(int userId, int sex, int age, int height, int weight, int lr_hand) {
        this.userid = ByteUtil.intToByte(userId);
        this.sex = (byte) (sex & 0xff);
        this.age = (byte) (age & 0xff);
        this.height = (byte) (height & 0xff);
        this.weight = (byte) (weight & 0xff);
        this.lr_hand = (byte) (lr_hand & 0xff);
    }

    public void setUserid(int id) {
        this.userid = ByteUtil.intToByte(id);
    }

    protected K2_SendUserInfo(Parcel in) {
        userid = in.createByteArray();
        sex = in.readByte();
        age = in.readByte();
        height = in.readByte();
        weight = in.readByte();
        lr_hand = in.readByte();
    }

    public static final Creator<K2_SendUserInfo> CREATOR = new Creator<K2_SendUserInfo>() {
        @Override
        public K2_SendUserInfo createFromParcel(Parcel in) {
            return new K2_SendUserInfo(in);
        }

        @Override
        public K2_SendUserInfo[] newArray(int size) {
            return new K2_SendUserInfo[size];
        }
    };

    public byte[] getBytes() {
        byte[] bytes = new byte[userid.length + 5];
        System.arraycopy(userid, 0, bytes, 0, userid.length);
        bytes[4] = sex;
        bytes[5] = age;
        bytes[6] = height;
        bytes[7] = weight;
        bytes[8]=lr_hand;
        return bytes;
    }

    public static int getItemSize() {
        return 9;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeByteArray(userid);
        dest.writeByte(sex);
        dest.writeByte(age);
        dest.writeByte(height);
        dest.writeByte(weight);
        dest.writeByte(lr_hand);
    }

    @Override
    public CEDevData toCEDevData() {
        CEDevData data=new CEDevData();
        data.setCmd(CEBC.K2.CMD_TYPE_SEND);
        data.setDataType(CEBC.K2.DATA_TYPE_USERINFO);
        data.setData(getBytes());
        data.setItemL(getItemSize());
        data.setItemNumber(1);
        return data;
    }

}
